<template>
  <avue-crud :data="data"
             v-model="form"
             :before-open="beforeOpen"
             :option="option"></avue-crud>
</template>
<script>
export default {
  data () {
    return {
      form: {},
      data: [{
        name: '张三',
        sex: '男'
      }],
      option: {
        column: [
          {
            label: '姓名',
            prop: 'name'
          }, {
            label: '性别',
            prop: 'sex'
          }
        ]
      },
    };
  },
  methods: {
    beforeOpen (done, type) {
      this.$alert(`我是${type}`, {
        confirmButtonText: '确定',
        callback: action => {
          if (['view', 'edit'].includes(type)) {
            // 查看和编辑逻辑
          } else {
            //新增逻辑
            this.form.name = '初始化赋值'
          }
          done();
        }
      });

    }
  }
};
</script>